package com.cat.yygh.user.controller.user;


import com.cat.yygh.common.result.R;
import com.cat.yygh.common.util.JwtHelper;
import com.cat.yygh.model.user.UserInfo;
import com.cat.yygh.user.service.UserInfoService;
import com.cat.yygh.vo.user.LoginVo;
import com.cat.yygh.vo.user.UserAuthVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-11-15
 */
@RestController
@RequestMapping("/user/userinfo")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;
    @PostMapping("/login")
    public R login(@RequestBody LoginVo loginVo){
         Map<String, Object> userInfo = userInfoService.login(loginVo);
        return R.ok().data("info",userInfo);
    }
    @GetMapping("/info")
    public R getUserInfo(@RequestHeader String token){
        Long userId = JwtHelper.getUserId(token);
        UserInfo userInfo = userInfoService.getUserInfo(userId);
        return R.ok().data("info",userInfo);
    }
    @PutMapping("/update")
    public R update(@RequestHeader String token,UserAuthVo userAuthVo){
        Long userId = JwtHelper.getUserId(token);
        userInfoService.update(userId,userAuthVo);
        return R.ok();
    }

}

